#!/bin/sh

# Determine the path to this application.
CURDIR="`pwd`"
APPDIR=`dirname "$0"`
cd "${APPDIR}"
APPDIR="`pwd`"
cd "${CURDIR}"

# Root check
[ ! "`whoami`" = "root" ] && exec gksu $0 "$@"

# Get translations
ENVIRONMENT_LANG=`echo $LANG | sed "s/\(..\).*/\1/"` #detect environment language 
case $ENVIRONMENT_LANG in
	de)	export LANGUAGE="german" ;;
	en)	export LANGUAGE="english" ;;
	es)	export LANGUAGE="spanish" ;;
	fr)	export LANGUAGE="french" ;;
	it)	export LANGUAGE="italian" ;;
	nb)	export LANGUAGE="norwegian" ;; #translation is norwegian bokmål
	nl)	export LANGUAGE="dutch" ;;
	nn)	export LANGUAGE="norwegian" ;; #Use norwegian bokmål, since there is no norwegian nynorsk
	ru)	export LANGUAGE="russian" ;;
	*)	export LANGUAGE="english" ;; #english for contries without translation
esac
. $APPDIR/locale/english.po #always run to fill gaps in translation
[ -f "$APPDIR/locale/${LANGUAGE}.po" ] && . $APPDIR/locale/${LANGUAGE}.po 2> /dev/null

ACTION="$1"
[ "$ACTION" = "" ] && ACTION="-conf"
case "$ACTION" in
 -conf)
 CONF="/etc/rc.firewall"
 $APPDIR/functions -buildlist
 export CONF_DLG="
 <window title=\"$LOC_MAIN\" icon_name=\"gtk-preferences\" window-position=\"1\">
  <vbox>
   <frame $LOC_OPEN_PORTS>
    <hbox>
     <vbox>
      <tree icon=\"gtk-connect\">
       <label>$LOC_PORTSTREE</label>
       <width>260</width>
       <variable>OPENPORTS</variable>
       <input>$APPDIR/functions -buildlist</input>
      </tree>
     </vbox>
     <vbox>
      <button>
       <input file stock=\"gtk-add\"></input>
       <label>$LOC_ADD</label>
       <action>$APPDIR/functions -add</action>
       <action type=\"refresh\">OPENPORTS</action>
      </button>
      <button>
       <input file stock=\"gtk-delete\"></input>
       <label>$LOC_DELETE</label>
       <action>$APPDIR/functions -delete \$OPENPORTS</action>
       <action type=\"refresh\">OPENPORTS</action>
      </button>
      <button>
       <input file icon=\"go-next\"></input>
       <label>$LOC_START</label>
       <action>$APPDIR/functions -start</action>
      </button>
      <button>
       <input file stock=\"gtk-stop\"></input>
       <label>$LOC_STOP</label>
       <action>$APPDIR/functions -stop</action>
      </button>
      <button>
       <input file stock=\"gtk-refresh\"></input>
       <label>$LOC_RESTART</label>
       <action>$APPDIR/functions -restart</action>
      </button>
     </vbox>
    </hbox>
   </frame>
   <hbox>
     <button>
      <input file stock=\"gtk-quit\"></input>
      <label>$LOC_QUIT</label>
     </button>
    </hbox>
  </vbox>
 </window>
 "
 gtkdialog3 --program CONF_DLG
 ;;
 -start)
 exec $APPDIR/functions -start
 ;;
 -stop)
 exec $APPDIR/functions -stop
 ;;
 -restart)
 exec $APPDIR/functions -restart
 ;;
esac
